@extends('Admin.layouts.common')

@section('content')
    <div class="container myContainer">

        <div id="order_tag"></div>

        <div class="table-responsive">
            @if (count($errors) > 0)
            <div class="alert alert-danger">
                <ul style="color:red;">
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
                </ul>
            </div>
            @endif
            

            <table class="table">
                <caption>结算明细，请仔细核对</caption>
                <thead>
                    <tr>
                        <th>
                            <a href="javascript:;" onclick="unall()">全选</a>
                            <button onclick="batch_refund()" class="btn-default btn-xs">批量结算</button>
                        uid</th>
                        <th>结算汇率</th>
                        <th>当月补贴金币数</th>
                        <th>当月补贴金币数结算</th>
                        <th>分成总金币数</th>
                        <th>分成总金币数结算</th>
                        <th>实际到账金额RMB</th>
                        
                        <!--
                        <th>计算完成后分成金额数</th>
                        <th>旗下合伙人带来的50%收益总数</th>
                        -->

                        <th>活跃用户量</th>
                        <th>新增用户量</th>
                        <th>时间</th>
                        <th>状态</th>
                        <th>结算操作</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($list as $item)
                        <tr>
                            <td>
                                @if($item->pay_status!=1)
                                <input type="checkbox" name="ids[]" value="{{$item->uid.'.'.$month}}">
                            @endif

                                {{ $item->uid }}</td>
                            <td>{{ $partner_proportion }}</td>
                            <td>{{ $item->subsidy_coin }}</td>
                            <td>{{ round($item->subsidy_coin/1000,2) }}</td>
                            <td>{{ $item->divide_into_coin }}</td>
                            <td>{{ round($item->divide_into_coin * $partner_proportion/1000,2) }}</td>
                            <td>{{ $item->money_all }}</td>
                           <!-- 
                            <td>{{ $item->after_divide_into_coin }}</td>
                            <td>{{ $item->subgrade_coin }}</td>
                        -->

                            <td>{{ $item->active_count }}</td>
                            <td>{{ $item->added_count }}</td>
                            <td>{{ $month}}</td>
                            <td>
                                @if($item->pay_status==1)
                                <span style="color: #6E8B3D">已结算</span>
                                @else
                                未结算
                                @endif
                            </td>
                            <td>
                                @if($item->pay_status!=1)
                                <a href="javascript:;" onclick="confirmpay('/user/onedone?month={{$month}}&uid={{$item->uid}}')">结算</a>
                                @endif

                            </td>
                        </tr>
                    @empty
                        <tr><td class="text-center" colspan="11">没有数据</td></tr>
                    @endforelse
                </tbody>
            </table>
            <div class="text-center">
                <!--
                <form method="post" action="/user/done">
                    {{ csrf_field() }}
                    <input type="hidden" name="month" value="{{$month}}">
                <button class="btn btn-primary" type="submit">&nbsp;&nbsp;确认无误结算&nbsp;&nbsp;</button>
                </form>
                -->
            </div>
        </div>

    </div>
@endsection

@section('foot')
<script type="text/javascript">
$.ajaxSetup({
    headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
})

function unall(){
    $('input').iCheck('toggle');
}

function batch_refund(){
    var a = $("input[name='ids[]']:checked").length;
    if(a==0){
        alert("请选择结算项");
        return false;
    }
    var ids = "";
    $("input[name='ids[]']:checked").each(function(i){
        if (i == 0) {
            ids = this.value;//循环每个值
        } else {
            ids += "," + this.value;
        }
    });
    if(confirm("您选择了"+a+"个项目，确定要批量结算吗？")){
        $.post("/user/ajax_batch_done",{ids:ids},function(json){
            if(json.status==1){
                window.location.reload();
            }else{
                alert(json.msg);
            }
        },"json");
    }
}

function confirmpay(url){
    if(confirm("确认结算吗?")){
        window.location.href=url;
    }
}
</script>
@endsection